// pages/select/select.js
const app = getApp();
var _tousList = [{
  name: '样 式 1',
  coverImgUrl: '../../images/ah1.png'
}, {
    name: '样 式 2',
  coverImgUrl: '../../images/ah2.png'
}, {
    name: '样 式 3',
  coverImgUrl: '../../images/ah3.png'
}, {
    name: '样 式 4',
  coverImgUrl: '../../images/ah4.png'
}
,
{
  name: '样 式 5',
  coverImgUrl: '../../images/ah5.png'
}
,
{
  name: '样 式 6',
  coverImgUrl: '../../images/ah6.png'
}
,
{
  name: '样 式 7',
  coverImgUrl: '../../images/ah7.png'
}
,
{
  name: '样 式 8',
  coverImgUrl: '../../images/ah8.png'
}
,
{
  name: '样 式 9',
  coverImgUrl: '../../images/ah9.png'
}
]

Page({

  /**
   * 页面的初始数据
   */
  data: {
    touList: _tousList,
    hasUserInfo: false, 
    userAvatarUrl: '' 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var hasUserInfo = false 
    var avatarUrl = options.avatarUrl 
    var that = this
    // string转bool 
    if(options.hasUserInfo == 'true') 
      hasUserInfo = true; 
    this.setData({ 
      hasUserInfo: hasUserInfo, 
      userAvatarUrl: avatarUrl 
    }) 
  },

  //点击选项进入详情页
  detail: function (e) {
    // console.log(e)
    var touNum = e.currentTarget.dataset.tounum
    var avatarUrl = this.data.userAvatarUrl
    var hasUserInfo = this.data.hasUserInfo
    // console.log(yangzhiNum)
    if(avatarUrl){
      console.log(avatarUrl)
      switch (touNum) {
        case 0:
          app.globalData.toubgsrc = _tousList[0].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 1:
          app.globalData.toubgsrc = _tousList[1].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 2:
          app.globalData.toubgsrc = _tousList[2].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 3:
          app.globalData.toubgsrc = _tousList[3].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 4:
          app.globalData.toubgsrc = _tousList[4].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 5:
          app.globalData.toubgsrc = _tousList[5].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 6:
          app.globalData.toubgsrc = _tousList[6].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 7:
          app.globalData.toubgsrc = _tousList[7].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 8:
          app.globalData.toubgsrc = _tousList[8].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        case 9:
          app.globalData.toubgsrc = _tousList[9].coverImgUrl
          wx.navigateTo({
            url: `../madeph/madeph?avatar=${avatarUrl}&hasUserInfo=${hasUserInfo}`
          })
          break;
        default:
        //do nothing
      }
    }
  },

})